package com.tim.test.leetcode.simulation.huawei;

import java.util.Scanner;

public class SimulationOnline1 {

    public static void main(String[] args) {
        s1(args);
    }

    public static void s1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            if(a==0){
                return;
            }
            int num = 0;
            do{
                if(a==2){
                    a++;// 借一个
                }
                int temp = a/3;
                num += temp;
                a = a%3+temp;
            }while(a>1);
            System.out.println(num);
        }
    }

    public static void s2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        boolean isFirst = true;
        boolean[] bools = new boolean[500];// 记录数据
        int n=0;
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            if(isFirst){
                isFirst=false;
                n=a;
                continue;
            }
            if(--n<0){
                break;
            }
            if(!bools[a]){
                bools[a] = true;
            }
        }
        for (int i = 0; i < bools.length; i++) {
            if(bools[i]){
                System.out.println(i);
            }
        }

    }

    public static void s3() {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            str = str.toUpperCase();
            if(!str.startsWith("0X")){
                System.out.println(-1);
                return ;
            }
            str = str.substring(2);
            int b = 0, i=0;
            while(i<str.length()){
                int val = 0;
                char c = str.charAt(i);
                switch (c){
                    case 'A':
                        val=10;
                        break;
                    case 'B':
                        val=11;
                        break;
                    case 'C':
                        val=12;
                        break;
                    case 'D':
                        val=13;
                        break;
                    case 'E':
                        val=14;
                        break;
                    case 'F':
                        val=15;
                        break;
                    default:
                        val = Integer.valueOf(""+c);
                }
                if(val!=0){
                    for (int j = 0; j < str.length()-i-1; j++) {
                        val = val*16;
                    }
                }
                b += val;
                i++;
            }
            System.out.println(b);
        }
    }

}
